// packageStore/pages/profile/clerkcard/clerkcard.js
import {api,util} from '../../../../js/util';
import BasePage from '../../../../js/common/base-page'
import {qywx} from '../../../../js/modules/store';
import {config} from "../../../../js/modules/gloab";
var app = getApp();
BasePage({

  /**
   * 页面的初始数据
   */
  data: {
    pic:'',
    qrCode:'',
    imgDomain: api.imgDomain,
    enableOss: api.enableOss,
    host:api.host,
    headerBg:"",
    info:{},
    ContactBottomTip:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    qywx.getFollow(function(res){
      res = res || []
      // 数组去重，移除多余的手机号与姓名相同的数据
      let resMap = new Map()
      res = res.filter((item) => {
        let key = `${item.mobile}_${item.UserName}_${item.Name}`
        if (resMap.get(key)) {
          return false
        }
        resMap.set(key, true)
        return true
      })
      that.setData({
        info:res
      })
    })
    that.getWholesaleConfig();
  },
  /*
  *加载配置项参数
   */
  getWholesaleConfig() {
    var that = this;
    var fkid = app.dns.proprietorId;
    var fkflag = app.dns.proprietor;
    config.getWholesaleConfigs(
      fkid,
      fkflag,
      "Wholesale",
       (model)=> {
        // that.setData({
        //   richtext_ContactBottomTip: model.ContactBottomTip
        // })
         that.setData({
          ContactBottomTip: model.ContactBottomTip
         });
      });
  },
  /**
   * 保存图片
   */
  saveImg:function(e){
    var code = e.currentTarget.dataset.src;
    wx.downloadFile({
      url: code,
      success:function(res){
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success(res) {
            wx.showModal({
              content: '图片已保存到相册，赶紧晒一下吧~',
              showCancel: false,
              confirmText: '好的',
              confirmColor: '#333',
              success: function (res) {
                if (res.confirm) { }
              },
              fail: function (res) { }
            })
          },
          fail: function (res) {
            wx.showToast({
              title: "保存失败",
              icon: 'none',
              duration: 2000
            })
          }
        })
      }
    })
  },
  /**
   * 拨打电话
   */
  call:function(e){
    var mobile = e.currentTarget.dataset.mobile;
    wx.makePhoneCall({
      phoneNumber: mobile
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      headerBg: api.titleColor||"#e56b14"
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})